package InnerClassDemo;

// 匿名内部类

public class NicknameInnerClassDemo {
    public static void main(String[] args) {
        // 学生/老师都参与游泳
        // 方法1 类与接口
        Swim student1 = new Student();
        Swim teacher1 = new Teacher();
        student1.swimming();
        teacher1.swimming();

        // 方法2 匿名内部类直接修改
        Swim student2 = new Swim() {
            @Override
            public void swimming() {
                System.out.println("学生开始蛙泳");
            }
        };
        Swim teacher2 = new Swim() {
            @Override
            public void swimming() {
                System.out.println("老师开始狗刨");
            }
        };
        student2.swimming();
        teacher2.swimming();

    }

    public static void start(Swim s){
        System.out.println("开始");
        s.swimming();
        System.out.println("结束");
    }
}

// 以下内容为 类与接口实现功能,而非匿名内部类实现
interface Swim{
    void swimming();
}

class Student implements Swim{
    public void swimming(){
        System.out.println("学生开始游泳");
    }
}

class Teacher implements Swim{
    public void swimming(){
        System.out.println("老师开始游泳");
    }
}
